package com.training.spring.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {

    // RequestMapping-(方法/类)注解
    // 此处想要访问v1方法,需要是(类路径+方法路径)
    // 如此时:http://127.0.0.1:8080/hello/hello1
    @RequestMapping("/hello1")
    public String v1(){
        return "hello Spring Boot~";
    }
    @RequestMapping("/hello2")
    public String v2(){
        return "hello Spring Boot2~";
    }
    // 在同一个类下,方法路径不能相同.
    @RequestMapping("/hello3")
    public String v3(){
        return "hello Spring Boot3~";
    }
    // 有时,想对请求方法进行约束:"只允许GET请求"
    // method是一个数组,此时只有一个元素,则直接等于,当然也可以写
    //@RequestMapping(value = "hello4",method = {RequestMethod.GET})
    @RequestMapping(value = "/hello4",method = RequestMethod.GET)
    // 等同于 @GetMapping("/hello4")
    public String v4(){
        return "hello Spring Boot4~";
    }
    @RequestMapping(value = "/hello5",method =
            {RequestMethod.GET,RequestMethod.POST})
    public String v5(){
        return "hello Spring Boot5~";
    }
    @RequestMapping("/hello6")
    public String v6(String name){
        return "name:" + name;
    }

}